package com.sise.stuteaintersys.mapper;

import com.sise.stuteaintersys.bean.entity.Homework;
import com.sise.stuteaintersys.bean.entity.HomeworkExample;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public interface HomeworkMapper {
    int countByExample(HomeworkExample example);

    int deleteByExample(HomeworkExample example);

    int deleteByPrimaryKey(Integer id);

    @Delete("delete from homework where gmt_create = #{date}")
    int deleteListByDate(Date date);

    int insert(Homework record);

    int insertSelective(Homework record);

    /**
     *
     * 
     *@param  list
     *@return int
     *@date 2019/1/6
     *@time 23:17
     */
    int insertBatch(List<Homework> list);

    List<Homework> selectByExample(HomeworkExample example);

    Homework selectByPrimaryKey(Integer id);

    /**
     * 最新作业
     *
     *@param courseId
     *@return List<Homework>
     */
    @Select({"select * from homework where homework.course_id=#{courseId} and gmt_create = (SELECT gmt_create from homework GROUP BY gmt_create Order by gmt_create DESC limit 1)"})
    List<Homework> selectAllHomework(Integer courseId);

    /**
     *  返回作业列表
     *
     *@param courseId
     *@return List<Date>
     */
    @Select("SELECT DISTINCT gmt_create FROM homework where homework.course_id = #{id}")
    List<String> listHomework(Integer courseId);
    /**
     * 返回一次作业的内容
     *
     *@param date
     *@return
     */
    @Select("select * from homework where gmt_create = #{date} and course_id=#{courseId}")
    List<Homework>  getHomework(@Param("date")Date date, @Param("courseId") Integer courseId);

    int updateByExampleSelective(@Param("record") Homework record, @Param("example") HomeworkExample example);

    int updateByExample(@Param("record") Homework record, @Param("example") HomeworkExample example);

    int updateByPrimaryKeySelective(Homework record);

    int updateByPrimaryKey(Homework record);
}